package net.qktianxia.component.logger.orhanobut.disk;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import net.qktianxia.component.logger.IFormatStrategy;
import net.qktianxia.component.logger.ILogProxy;
import net.qktianxia.component.logger.orhanobut.format.CsvFormatStrategy;

import static net.qktianxia.component.logger.Utils.checkNotNull;

/**
 * This is used to saves log messages to the disk.
 * By default it uses {@link CsvFormatStrategy} to translates text message into CSV format.
 */
public class DiskLogProxy implements ILogProxy {

  @NonNull private final IFormatStrategy formatStrategy;

  public DiskLogProxy() {
    formatStrategy = CsvFormatStrategy.newBuilder().build();
  }

  public DiskLogProxy(@NonNull IFormatStrategy formatStrategy) {
    this.formatStrategy = checkNotNull(formatStrategy);
  }

  @Override public boolean isLoggable(int priority, @Nullable String tag) {
    return true;
  }

  @Override public void log(int priority, @Nullable String tag, @NonNull String message) {
    getIFormatStrategy().log(priority, tag, message);
  }

  @Override
  public IFormatStrategy getIFormatStrategy() {
    return formatStrategy;
  }
}
